package xkp.lesson1;

public class ReturnAndFinally extends Object{
	public static void main(String[] args) {
		System.out.println(fun1());
		System.out.println(fun2());
		System.out.println(fun3());
		System.out.println(fun4());
	}
	
	public static Person fun4() {

		Person person = new Person(20, "张三");
		try {
			//return要返回100，会把要返回的值(100)先压栈
			return person;
		} catch (Exception e) {
			// TODO: handle exception
		}finally {
			person = new Person(40, "李四");
			
		}
		return person;
	}

	public static Person fun3() {

		Person person = new Person(20, "张三");
		try {
			//return要返回100，会把要返回的值(100)先压栈
			return person;
		} catch (Exception e) {
			// TODO: handle exception
		}finally {
			person.setAge(30);
			
		}
		return person;
	}


	public static int fun2() {

		int count = 100;
		try {
			//return要返回100，会把要返回的值(100)先压栈
			return count;
		} catch (Exception e) {
			// TODO: handle exception
		}finally {
			count = 300;
		}
		return count;
	}

	//注意：finally中的return会覆盖try/catch中的return
	public static int fun1() {
		try {
			int n = 100/0;
			return 100;
		} catch (Exception e) {
			return 300;
		}finally {
			return 200;
		}
	}

}
